package com.czkj.hwz.decorate.Activity;

import android.os.Build;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.czkj.hwz.decorate.R;
import com.czkj.hwz.decorate.base.HttpUrl;
import com.czkj.hwz.decorate.bean.Rows;
import com.czkj.hwz.decorate.bean.Worker;
import com.czkj.hwz.decorate.bean1.ExamineEnterprise;
import com.czkj.hwz.decorate.bean1.User;
import com.king.base.BaseActivity;

import net.tsz.afinal.FinalBitmap;

import java.util.ArrayList;

public class WorkerDetailActivity extends BaseActivity {
    private static final String TAG = "WorkerDetailActivity";
    private TextView tvName;
    private Worker worker;
    private ExamineEnterprise examineEnterprise;
    private LinearLayout workers_ll;
    private FinalBitmap fb;
    private ImageView iv;
    private TextView operation_center_tv;
    @Override
    public void initUI() {
        if (Build.VERSION.SDK_INT >= 21){
            Window window = getWindow();
            //取消设置透明状态栏,使 ContentView 内容不再覆盖状态栏
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //需要设置这个 flag 才能调用 setStatusBarColor 来设置状态栏颜色
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            //设置状态栏颜色
            window.setStatusBarColor(getResources().getColor(R.color.yellow));
            getSupportActionBar().hide();
        }
        setContentView(R.layout.activity_worker_detail);
        getSupportActionBar().hide();
        tvName=findView(R.id.name);
        workers_ll=findView(R.id.workers_ll);
        iv=findView(R.id.photo);
        operation_center_tv=findView(R.id.operation_center_tv);
        ArrayList<Worker> workerList= (ArrayList<Worker>) getIntent().getSerializableExtra("workerList");
        ArrayList<ExamineEnterprise> examineEnterpriseList= (ArrayList<ExamineEnterprise>) getIntent().getSerializableExtra("examineEnterpriseList");
        ArrayList<User> userList= (ArrayList<User>) getIntent().getSerializableExtra("userList");
        int position=getIntent().getIntExtra("position",0);
        Log.d(TAG, "initUI: "+workerList.toString());
        Log.d(TAG, "initUI: "+examineEnterpriseList.toString());
        Log.d(TAG, "initUI: "+userList.toString());
        Log.d(TAG, "initUI: "+position);
        worker=workerList.get(position);
        examineEnterprise=examineEnterpriseList.get(position);
        if (fb==null) {
            fb=FinalBitmap.create(context);
            fb.configBitmapMaxHeight(150);
            fb.configBitmapMaxWidth(150);
        }
    }

    @Override
    public void initData() {
        tvName.setText(worker.getName());
        for (int i=0;i<worker.getWorkerTypeList().size();i++) {
            TextView tv=new TextView(context);
            LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);

            tv.setLayoutParams(layoutParams);
            if (i==0) {

            }else {
                tv.setPadding(15,0,0,0);
            }

            tv.setText(worker.getWorkerTypeList().get(i).getName());
            workers_ll.addView(tv);
        }
        fb.display(iv, HttpUrl.BASE_URL+worker.getPhoto());
        operation_center_tv.setText(examineEnterprise.getName());
    }

    @Override
    public void addListeners() {

    }
    public void OnClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
